package com.zf.museum.controller;


import com.zf.museum.bean.Question;
import com.zf.museum.bean.Result;
import com.zf.museum.model.MultiChoices;
import com.zf.museum.service.MultiChoicesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
@Api(description = "多选题")
@RestController
@RequestMapping("/multi")
public class MultiChoicesController {

    @Autowired
    private MultiChoicesService multiChoicesService;

    @ApiOperation(value = "上传题目", notes = "上传含有Excel表格的题目")
    @PostMapping("/upload")
    @RequiresRoles("admin")
    public Result upload(MultipartFile file) {
        System.out.println("上传成功");
        return multiChoicesService.upload(file);
    }

    @ApiOperation(value = "查看所有题目")
    @GetMapping("/findAll")
    @RequiresRoles("admin")
    public List<MultiChoices> findAll() {

        return multiChoicesService.findAll();
    }

    @ApiOperation(value = "修改题目内容", notes = "返回修改后的所有题目")
    @ApiImplicitParam(name = "multiChoices", value = "题目的集合", dataType = "MultiChoices")
    @PostMapping("/update")
    @RequiresRoles("admin")
    public Result update(@RequestBody List<MultiChoices> multiChoices) {
        return multiChoicesService.update(multiChoices);
    }

    @ApiOperation(value = "删除题目", notes = "返回删除的题数")
    @ApiImplicitParam(name = "ids", value = "题目id的集合", dataType = "Array[long]")
    @PostMapping("/delete")
    @RequiresRoles("admin")
    public Result delete(@RequestBody List<Long> ids) {

        return multiChoicesService.delete(ids);
    }

    @ApiOperation(value = "获取6道题目")
    @GetMapping("/getMultiChoices")
    public List<MultiChoices> getMultiChoices(@RequestParam("openId") String openId) {
        return multiChoicesService.getMultiChoices(openId);
    }

}
